package com.exer.basic.iterator;

import java.util.Arrays;
import java.util.Iterator;
import java.util.List;

public class IteratorDemo {
    public static void main(String[] args) {
        List<String> list = Arrays.asList("first", "second", "third", "fourth");
        for (Iterator<String> iter = list.iterator(); iter.hasNext(); ) {
            String next = iter.next();
            System.out.println(next);
            if ("second".equals(next)) {
                list.add("five");
            }
        }
    }
}
